package Test;

import java.util.Scanner;

public class Day7 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int f1=0;
        int f2=1;
        while(f2<n){
          int f3=f1+f2;
            f1=f2;
            f2=f3;

        }
        int min=Math.min(f2-n,n-f1);
        System.out.println(min);
    }
}
